<template>
    <div class="register">
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field
                    v-model="registerData.username"
                    name="用户名"
                    label="用户名"
                    placeholder="用户名"
                    :rules="[{ required: true, message: '请填写用户名' }]"
                />
                <van-field
                    v-model="registerData.password"
                    type="password"
                    name="密码"
                    label="密码"
                    placeholder="密码"
                    :rules="[{ required: false, message: '请填写密码' }]"
                />
                <van-field
                    v-model="registerData.age"
                    name="年龄"
                    label="年龄"
                    placeholder="年龄"
                    :rules="[{ required: true, message: '请填写年龄' }]"
                />
                <van-radio-group
                    @click="bindChange"
                    v-model="checked"
                    direction="horizontal"
                >
                    <van-radio name="0">男</van-radio>
                    <van-radio name="1">女</van-radio>
                </van-radio-group>
                <van-field
                    v-model="registerData.headerimg"
                    name="头像"
                    label="头像"
                    placeholder="请输入图片地址"
                    :rules="[{ required: false, message: '请输入图片地址' }]"
                />
                <van-field
                    v-model="registerData.nick"
                    name="昵称"
                    label="昵称"
                    placeholder="默认为游客"
                    :rules="[{ required: false, message: '请填写昵称' }]"
                />
                <van-field
                    v-model="registerData.visitgoal"
                    name="到访目的"
                    label="到访目的"
                    placeholder="请输入到访目的"
                    :rules="[{ required: false, message: '请填写到访目的' }]"
                />
                <van-field
                    v-model="registerData.education"
                    name="学历"
                    label="学历"
                    placeholder="请输入学历"
                    :rules="[{ required: false, message: '请填写学历' }]"
                />
                <van-field
                    v-model="registerData.company"
                    name="公司，单位"
                    label="公司，单位"
                    placeholder="请输入公司或者单位"
                    :rules="[
                        { required: false, message: '请填写公司或者单位' },
                    ]"
                />
            </van-cell-group>
            <van-cell title="登录" @click="toLogin" is-link />
            <div style="margin: 16px">
                <van-button round block type="primary" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>
        <van-action-sheet
            v-model:show="show"
            :actions="actions"
            @select="onSelect"
            description="注册成功，是否跳转到登录"
            cancel-text="取消"
            close-on-click-action
        />
    </div>
</template>

<script lang="ts" setup>

import { useRegister } from '@/hooks/register'
const { registerData, onSubmit, bindChange, checked, onSelect,show,actions,toLogin } = useRegister()
    
</script>

<style scoped lang="scss"></style>
